package com.yu.dv.strategy.metadata.impl;

import com.yu.dv.entity.TableInfo;
import com.yu.dv.strategy.metadata.MetadataTemplate;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

public class GenericMetadataStrategy extends MetadataTemplate {

    @Override
    protected String getCatalog(Connection connection) {
        try {
            return connection.getCatalog();
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    protected String getSchema(Connection connection) {
        try {
            return connection.getSchema();
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    protected String[] getTableTypes() {
        return new String[]{"TABLE", "VIEW"};
    }

    @Override
    protected List<TableInfo> getTablesWithFallback(Connection connection, String catalog, String schema) throws Exception {
        // 通用策略使用带重试的方法
        return new ArrayList<>(); // 返回空列表，让模版方法处理重试逻辑
    }

    @Override
    protected List<TableInfo> getTablesStandard(java.sql.DatabaseMetaData metaData,
                                                String catalog, String schema,
                                                String[] tableTypes) throws java.sql.SQLException {
        // 通用策略使用带重试的版本
        return getTablesWithRetry(metaData, catalog, schema, tableTypes);
    }
}